"use strict";
const { Model } = require("sequelize");
module.exports = (sequelize, DataTypes) => {
  class Inventory extends Model {
    //库存
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      Inventory.belongsTo(models.Product, {
        foreignKey: "product_id",
        onDelete: "CASCADE",
      });
      Inventory.belongsTo(models.Client, {
        foreignKey: "client_id",
        alloNull: true,
      });
      // define association here
    }
  }
  Inventory.init(
    {
      unit: DataTypes.STRING,
      price1: DataTypes.DOUBLE,
      number1: DataTypes.INTEGER,
      money1: DataTypes.DOUBLE,
      price2: DataTypes.DOUBLE,
      number2: DataTypes.INTEGER,
      money2: DataTypes.DOUBLE,
      in_time: DataTypes.DATE,
      price3: DataTypes.DOUBLE,
      number3: DataTypes.INTEGER,
      out_time: DataTypes.DATE,
      money3: DataTypes.DOUBLE,
      price4: DataTypes.DOUBLE,
      number4: DataTypes.INTEGER,
      money4: DataTypes.DOUBLE,
      remarks: DataTypes.STRING,
    },
    {
      sequelize,
      modelName: "Inventory",
      tableName: "inventories",
    }
  );
  return Inventory;
};
